package domain.cron;

import java.io.IOException;
import java.util.List;

import javax.jdo.JDOHelper;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import domain.data.QnAPersistenceManager;
import domain.model.Domain;
import domain.model.KillKeyword;
import domain.service.AgeDomain;
import domain.service.AlexaUpdate;
import domain.service.CheckRobotSitemap;
import domain.service.GooglePageRank;
import domain.service.Ip;
import domain.service.SelfSiteUpdate;

@SuppressWarnings("serial")
public class UpdateKillKeywordServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		resp.setContentType("text/plain");
		resp.getWriter().println("Hello, world");
		
		int title_url = Integer.parseInt(req.getParameter("name"));
		PersistenceManager psm = QnAPersistenceManager.get().getPersistenceManager();
		Query query = psm.newQuery(Domain.class);
		query.setFilter("sex==1 && field9==0");
		query.setRange(title_url,title_url+1);
		@SuppressWarnings("unchecked")
		List<Domain> domains = (List<Domain>) query.execute();
		if(domains.size()>0)
		{
			for(int i=0;i<domains.size();i++)
			{
				domains.get(i).setField9(1);
				psm=JDOHelper.getPersistenceManager(domains.get(i));
				psm.currentTransaction().begin();
				psm.makePersistent(domains.get(i));
				psm.currentTransaction().commit();
				for(int j=0;j<domains.get(i).getKeywords().size();j++)
				{
					KillKeyword kill = new KillKeyword();
					kill.setName(domains.get(i).getKeywords().get(j).toString());
					kill.setDomain(domains.get(i).getName());
					psm.makePersistent(kill);
				}
			}
		}
	}

}
